package master;

/**
 *
 * 回文数
 *
 * @author chenyw
 * @date 2022/7/23 10:33
 */
public class M9isPalindrome {
/*    //转为字符串
    public boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }
        if (x >= 0 && x <= 9) {
            return true;
        }
        String s = Integer.toString(x);
        int i = 0;
        int j = s.length() - 1;
        while (i < j && s.charAt(i) == s.charAt(j)) {
            i++;
            j--;
        }
        return i >= j ? true : false;
    }*/

    //不转为字符串，防止溢出翻转一般数字
    public boolean isPalindrome(int x) {
        if (x < 0 || (x % 10 == 0 && x != 0)) {
            return false;
        }
        int tmp = 0;
        while (x > tmp) {
            tmp = tmp * 10 + x % 10;
            x /= 10;
        }
        return x == tmp || x == tmp / 10;

    }

}
